﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace POC.Loggers.Storage
{
    /*
    public abstract class CloudTraceListener : TraceListener
    {
        private bool initialized;
        protected CloudStorageAccount storageAccount;
        protected StringDictionary settings;
        protected bool async;
        protected List<Task> tasks;
        protected bool plainTextMessages;

        #region TraceListener
        protected override string[] GetSupportedAttributes()
        {
            return Enum.GetNames(typeof(SupportedAttributes));
        }
        #endregion

        #region .ctor
        protected CloudTraceListener(string initializeData)
            : base()
        {
            this.settings = Util.ParseInitData(initializeData);
        }
        #endregion

        protected virtual void Initialize()
        {
            if (!initialized)
            {
                if (bool.Parse(Attributes[SupportedAttributes.useDevStorage.ToString()] ??
                    settings[SupportedAttributes.useDevStorage.ToString()] ?? bool.FalseString))
                {
                    this.storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
                }
                else
                {
                    string connectionString = Attributes[SupportedAttributes.connectionStringName.ToString()];

                    if (string.IsNullOrEmpty(connectionString))
                    {
                        string key, account;
                        account = Attributes[SupportedAttributes.account.ToString()] ?? settings[SupportedAttributes.account.ToString()];
                        key = Attributes[SupportedAttributes.accessKey.ToString()] ?? settings[SupportedAttributes.accessKey.ToString()];
                        storageAccount = new CloudStorageAccount(new StorageCredentials(account, key), true);
                    }
                    else
                    {
                        storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(connectionString));
                    }
                }

                this.async = bool.Parse(Attributes[SupportedAttributes.async.ToString()] ??
                    settings[SupportedAttributes.async.ToString()] ?? bool.FalseString);
                if (async)
                    this.tasks = new List<Task>();
                this.plainTextMessages = bool.Parse(Attributes[SupportedAttributes.usePlainText.ToString()] ??
                    settings[SupportedAttributes.usePlainText.ToString()] ?? bool.FalseString);
                initialized = true;
            }
        }

        protected abstract void InitializeService();

        public override void Flush()
        {
            if (async)
                Task.WaitAll(tasks.ToArray());
            base.Flush();
        }

        public override void Close()
        {
            this.Flush();
            base.Close();
        }

        #region Write/WriteLine
        public override void Write(string message)
        {
            this.WriteLine(message);
        }

        public override void Write(object o)
        {
            this.WriteLine(Convert.ToString(o));
        }

        public override void Write(object o, string category)
        {
            this.WriteLine(Convert.ToString(o), category);
        }

        public override void Write(string message, string category)
        {
            this.WriteLine(message, category);
        }

        public override void WriteLine(string message)
        {
            this.WriteLine(message, null);
        }

        public override void WriteLine(object o)
        {
            this.WriteLine(Convert.ToString(o), null);
        }

        public override void WriteLine(object o, string category)
        {
            base.WriteLine(Convert.ToString(o), category);
        }

        public override void WriteLine(string message, string category)
        {
            if (string.IsNullOrEmpty(message))
                return;

            LogMessage logMessage = new LogMessage(message, category);
            this.SaveMessage(logMessage);
        }
        #endregion

        #region TraceEvent/TraceData
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            if ((this.Filter == null) || this.Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data, null))
            {
                string message = string.Empty;
                if (data != null)
                {
                    message = data.ToString();
                }
                LogMessage logMessage = new LogMessage(source, eventType, id, eventCache, TraceOutputOptions, message);
                this.SaveMessage(logMessage);
            }
        }

        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data)
        {
            if ((this.Filter == null) || this.Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, data))
            {
                StringBuilder builder = new StringBuilder();
                if (data != null)
                {
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (i != 0)
                        {
                            builder.Append(", ");
                        }
                        if (data[i] != null)
                        {
                            builder.Append(data[i].ToString());
                        }
                    }
                }
                LogMessage logMessage = new LogMessage(source, eventType, id, eventCache, TraceOutputOptions, builder.ToString());
                this.SaveMessage(logMessage);
            }
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
        {
            base.TraceEvent(eventCache, source, eventType, id);
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            if ((this.Filter == null) || this.Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
            {
                LogMessage logMessage = new LogMessage(source, eventType, id, eventCache, TraceOutputOptions, message);
                this.SaveMessage(logMessage);
            }
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if ((this.Filter == null) || this.Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
            {
                LogMessage logMessage = new LogMessage(source, eventType, id, eventCache, TraceOutputOptions,
                    args != null ? string.Format(CultureInfo.InvariantCulture, format, args) : format);
                this.SaveMessage(logMessage);
            }
        }

        public override void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId)
        {
            base.TraceTransfer(eventCache, source, id, message, relatedActivityId);
        }
        #endregion

        protected abstract void SaveMessage(LogMessage logMessage);
    }
    */
 public   class AzureStorageTraceListener : TraceListener
    {
     public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
     {

         base.TraceData(eventCache, source, eventType, id, data);
     }
    }
}
